/**
 * 用户相关API
 */

import { request } from './request';
import type { UserInfo, LoginParams } from '../types/user';

/**
 * 微信登录
 */
export const wxLogin = (code: string) => {
  return request.post<{
    token: string;
    userInfo: UserInfo;
  }>('/user/wx-login', { code });
};

/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return request.get<UserInfo>('/user/info');
};

/**
 * 更新用户信息
 */
export const updateUserInfo = (data: Partial<UserInfo>) => {
  return request.put<UserInfo>('/user/update', data);
};

/**
 * 获取用户发布的商品
 */
export const getUserGoods = (params?: { page?: number; pageSize?: number }) => {
  return request.get('/user/goods', params);
};

/**
 * 获取用户收藏的商品
 */
export const getUserFavorites = (params?: { page?: number; pageSize?: number }) => {
  return request.get('/user/favorites', params);
};

/**
 * 收藏/取消收藏商品
 */
export const toggleFavorite = (goodsId: string) => {
  return request.post('/user/favorite/toggle', { goodsId });
};